<?php

namespace App\Shx\Model;

class VirtualFile extends BaseFile
{
    const FILE_RAW = 'raw';

    protected function saveFile($file)
    {
        $this->disk->putFileAs($this->path.$this->file_name, $file, self::FILE_RAW);
        return $this;
    }

    public function getContent()
    {
        $anchor = $this->anchor ? $this->anchor : self::FILE_RAW;
        if(!$this->disk->exists($this->path.$this->file_name.self::PATH_BREAK.$anchor)) {
            $this->make();
        }

        return $this->disk->get($this->fullpath);
    }

    public function make()
    {
        $this->disk->putFileAs($this->path.$this->file_name, $file, $this->anchor);
    }

    public function __get($key)
    {
        switch ($key) {
            case 'fullpath' :
                $realFileName = self::FILE_RAW;
                return $this->path.$this->file_name.self::PATH_BREAK.$realFileName;
        }

        return parent::__get($key);
    }
}